# Gilardi, Fabrizio, "The Temporary Importance of Role Models for Women's Political Representation", American Journal of Political Science
# Code to replicate Table SI16 (Replication of Table 1, with count explanatory variables measured as factors or dichotomously)
# gilardi@ipz.uzh.ch, 2014-06-24

# Set working directory
setwd("../Data/")

# Load packages
library(texreg)

# Load data
d <- read.csv("dataset-full.csv")


###################
# Estimate models #########################################
###################

out.1w <- glm(n.women.cand ~ sl.autob.n.women.elected + as.factor(n.women.elected.lagged) + as.factor(n.women.cand.previously.elected) + as.factor(n.men.cand.previously.elected) + as.factor(n.women.cand.lagged) + n.people.elected + n.cand + referenda + wom.kr + log.dist.zh + log.pop +  kr.svp + steuerfuss + as.factor(stadt.land) + sl.autob.n.women.elected*as.factor(year), data=d, family="poisson")
summary(out.1w)

out.2w <- glm(n.women.cand ~ sl.autob.n.women.elected + I(n.women.elected.lagged > 0) + I(n.women.cand.previously.elected > 0) + I(n.men.cand.previously.elected > 0) + I(n.women.cand.lagged > 0) + n.people.elected + n.cand + referenda + wom.kr + log.dist.zh + log.pop +  kr.svp + steuerfuss + as.factor(stadt.land) + sl.autob.n.women.elected*as.factor(year), data=d, family="poisson")
summary(out.2w)



##############
# Make table ########################################
##############

var.names <- c(
	"(Intercept)",
	"Spatial lag",
	"Nr. xfemale elected = 1 ($t-1$)",
	"Nr. xfemale elected = 2 ($t-1$)",
	"Nr. xfemale elected = 3 ($t-1$)",
	"Nr. xfemale elected = 4 ($t-1$)",
	"Nr. xfemale incumbent cand. = 1 ($t-1$)",
	"Nr. xfemale incumbent cand. = 2 ($t-1$)",
	"Nr. xfemale incumbent cand. = 3 ($t-1$)",
	"Nr. xfemale incumbent cand. = 4 ($t-1$)",
	"Nr. xmale incumbent cand. = 1 ($t-1$)",
	"Nr. xmale incumbent cand. = 2 ($t-1$)",
	"Nr. xmale incumbent cand. = 3 ($t-1$)",
	"Nr. xmale incumbent cand. = 4 ($t-1$)",
	"Nr. xmale incumbent cand. = 5 ($t-1$)",
	"Nr. xmale incumbent cand. = 6 ($t-1$)",
	"Nr. xmale incumbent cand. = 7 ($t-1$)",
	"Nr. xmale incumbent cand. = 8 ($t-1$)",
	"Nr. xmale incumbent cand. = 10 ($t-1$)",
	"Nr. xfemale cand. = 1 ($t-1$)",
	"Nr. xfemale cand. = 2 ($t-1$)",
	"Nr. xfemale cand. = 3 ($t-1$)",
	"Nr. xfemale cand. = 4 ($t-1$)",
	"Nr. xfemale cand. = 5 ($t-1$)",
	"Nr. xfemale cand. = 6 ($t-1$)",
	"Nr. xfemale cand. = 7 ($t-1$)",
	"Nr. seats",
	"Total nr. candidates",
	"Referenda on gender equality",
	"Support for xfemale in cantonal elec.",
	"Distance from Zurich (log)",
	"Population (log)",
	"Support for conservative party",
	"Tax level",
	"Suburb",
	"Countryside",
	seq(1978, 2010, 4),
	"Spatial lag $xx$ 1978",
	"Spatial lag $xx$ 1982",
	"Spatial lag $xx$ 1986",
	"Spatial lag $xx$ 1990",
	"Spatial lag $xx$ 1994",
	"Spatial lag $xx$ 1998",
	"Spatial lag $xx$ 2002",
	"Spatial lag $xx$ 2006",
	"Spatial lag $xx$ 2010",
	"Nr. xfemale elected > 0 ($t-1$)",
	"Nr. xfemale incumbent cand. > 0 ($t-1$)",
	"Nr. xmale incumbent cand. > 0 ($t-1$)",
	"Nr. xfemale cand. > 0 ($t-1$)"
)

model.names <- c("(1)", "(2)")

texreg(list(out.1w, out.2w), single.row=T, center=T, dcolumn=T, custom.coef.names=var.names, custom.model.names=model.names)



